package com.itheima.dao;

import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CheckItemDao {

    /**
     * 新增CheckItem数据项
     * @param checkItem 检查项实体类
     */
    @Insert("insert into t_checkitem values(null,#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#{attention})")
    public void add(CheckItem checkItem);

    /**
     * 查询全部
     * @return 全体检查项集合
     */
    @Select("select * from t_checkitem")
    public List<CheckItem> getAll();

    /**
     * 模糊查询
     * @param value
     * @return
     */
    @Select("select * from t_checkitem where code=#{value} or name like concat('%',#{value},'%')")
    public List<CheckItem> getByLike(@Param("value") String value);

    /**
     * 根据id删除数据
     * @param id
     */
    @Delete("delete from t_checkitem where id=#{id}")
    public void delete(@Param("id") Integer id);

    /**
     * 跟新检查项数据
     * @param checkItem
     */
    @Update("update t_checkitem set code=#{code},name=#{name},sex=#{sex},age=#{age},price=#{price},type=#{type},remark=#{remark},attention=#{attention} where id=#{id}")
    public void update(CheckItem checkItem);

    @Select("select count(*) from t_checkgroup_checkitem where checkitem_id=#{id}")
    public long getForeignKeyByCheckItemId(Integer id);

    @Select("select * from t_checkitem where id in (select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{checkgroup_id})")
    public List<CheckItem> findByInnerId(@Param("checkgroup_id") Integer id);

}
